<?php

/*
 * 
 * 
 */
$start = microtime(true);
define('ABSPATH', dirname(__FILE__) . '/');
if (function_exists('xdebug_start_trace')) {
    //xdebug_start_trace(ABSPATH . 'trace.xt' . uniqid());
}
set_time_limit(0);
ob_implicit_flush(true);
require_once('include.all.php');

//die('qwe');
$classname = 'multiCURL';
$timer = Tick::getInstance();
$queue = new TaskQueue(50);
for ($i = 0; $i < 100; $i++) {
    $curl = new multiCURL('http://ya.ru/');
    $queue->addTask($curl);
    $curl->addEventListener('onLoad', function(Event $event) {
                $result = $event->target->result;
                $info = $event->target->info;
                var_dump(strlen($result));
                echo "OK<br>\n";
                $event->target->removeEventListener($event->type, $event->callee);
            });
    unset($curl);
}

/* $timer_out = setInterval(function(){
  echo "time: ".time()."\n";
  file_put_contents(ABSPATH . 'total.ser',var_export( array(EventDispatcher::$total,
  DWebBrowserEvents2::$total), true ) );
  }, 1); */

$timer->startExecution();

echo 'end: ' . (microtime(true) - $start);
//register_shutdown_function
//register_tick_function